/*
注意：
此学生管理系统（Student Management System，简称SMS）不适用于大量数据展示。
因为程序会把所有信息推到网页上，无论该行数据是否需要展示，
然后再将无需展示的数据进行隐藏。
因此，在处理大量数据时很可能造成程序卡顿，甚至崩溃。
*/


// 日期校验用正则
const dateExp = /((^((1[8-9]\d{2})|(2[0-4]\d{2}))(-)(10|12|0?[13578])(-)(3[01]|[12]\d|0?[1-9])$)|(^((1[8-9]\d{2})|(2[0-4]\d{2}))(-)(11|0?[469])(-)(30|[12]\d|0?[1-9])$)|(^((1[8-9]\d{2})|(2[0-4]\d{2}))(-)(0?2)(-)(2[0-8]|1\d|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^(1[89]0[48])(-)(0?2)(-)(29)$)|(^(2\d0[48])(-)(0?2)(-)(29)$)|(^(1[89][2468][048])(-)(0?2)(-)(29)$)|(^(2\d[2468][048])(-)(0?2)(-)(29)$)|(^(1[89][13579][26])(-)(0?2)(-)(29)$)|(^(2[0-4][13579][26])(-)(0?2)(-)(29)$))/;
// 可选的数据源
let data0 = null;
let data13 = [
    {
        id: 12123010109,
        name: "zky",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }];
let data97 = [
    {
        id: 12123010109,
        name: "zky",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 1,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 2,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 3,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 4,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 5,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 6,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    },
    {
        id: 7,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 8,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 9,
        name: "jack",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 10,
        name: "rose",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 11,
        name: "tom",
        gender: "男",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }, {
        id: 12,
        name: "jerry",
        gender: "女",
        academy: "学院一",
        major: "专业一",
        telephone: "12345678",
        enrolledDate: new Date()
    }];
// 设置数据源
let data = data97;

// 获取表体元素
let content = document.querySelector("#students-content-table-content");
// 获取弹窗（增加+修改界面）
let adder = $('#adder');
let updater = $('#updater');
// 获取必要元素
let selectedRow;// 修改定位用
let pages = 1;// 总页数 从1开始
let currentPage = 0;// 当前页 0为初始状态，从1开始
let pageBtn = document.getElementById('pagination-buttons');// 页数按钮
let allRows = content.children.length;
let showRows = 10;// 展示行数


// 初始化
console.log("初始化...");
setData(data);
sort();

// 加载数据
function setData(data) {
    // 清空
    clearData();
    // 遍历数据 进行元素创建
    if (data != null) {
        for (let i = 0; i < data.length; i++) {
            let d = data[i];
            add(d.id, d.name, d.gender, d.academy, d.major, d.telephone, d.enrolledDate);
        }
        console.log("加载数据完成，共添加" + data.length + "条");
    } else console.log("完成，没有数据供加载");
}

// 清空展示数据
function clearData() {
    let first = content.firstElementChild;
    while (first) {
        first.remove();
        first = content.firstElementChild;
    }
}

/*
翻页
 */

// 设置分页
function paginate() {
    // 获取展示行数
    showRows = getShowRows();
    // 行数所需展示高度
    setTableHeight(showRows);
    // 设置展示页数
    setPages(showRows);
    // 切换至第1页 默认
    goToPage(1);
}

// 宽度
function setTableHeight(showRows) {
    let h = $('#students-content');
    if (showRows <= 10) h.prop('style').height = '490px';
    else if (showRows <= 30) h.prop('style').height = '1410px';
    else if (showRows <= 100) h.prop('style').height = '4580px';
}

// 获取每页的行数
function getShowRows() {
    let index = $('#sort-single').prop('selectedIndex');// 获取被选择项的索引
    let showRows = $('#sort-single option').eq(index).prop('value');// 获取展示行数
    return parseInt(showRows);// 转换一下类型，不转换不行
}

// 设置展示总页数
function setPages(showRows) {
    // 计算所需页数
    let temp = pages;// 用于储存页数变化值
    pages = Math.ceil(content.children.length / showRows);// 向上取整
    if (pages === 0) pages = 1;

    // 设置页数按钮
    if (temp < pages) {// 页数变多
        for (let i = temp + 1; i <= pages; i++) // 从后一项（新的一页）开始
            addPagesBtn(i);
    } else if (temp > pages) {// 页数变少
        clearPagesBtn();
        for (let i = 2; i <= pages; i++) addPagesBtn(i);
    }
}

// 增加页数按钮
function addPagesBtn(pageNo) {
    // 添加其他页数按钮
    $('<button ' +
        'class="pagination-button pagination-button-others pagination-button-in" ' +
        'style="margin-right: 4px" ' +
        'onclick="goToPage(' + pageNo + ')">' +
        pageNo + '</button>').appendTo(pageBtn);
}

// 清空页数按钮
function clearPagesBtn() {
    let buttons = $('.pagination-button-others');
    if (buttons !== null) buttons.remove();
}

// 翻页
function goToPage(pageNo) {
    // 避免超限
    if (pageNo < 1) pageNo = 1;
    if (pageNo > pages) pageNo = pages;
    // 需要页数或行数变化
    if (pageNo !== currentPage || allRows !== content.children.length) {
        // 计算 展示行的 位置
        let bottomRow = (pageNo - 1) * showRows;// 起始行 0开始
        let topRow = pageNo * showRows;// 结束行
        let allRows = content.children.length;// 总行数
        // 限制 结束行的值 不超过最大值（总行数）
        if (topRow > allRows) topRow = allRows;

        // 隐藏所有数据
        for (let i = 0; i < allRows; i++) {
            content.children[i].classList.remove('show-row');
            content.children[i].classList.add('hidden-row');
        }
        // 展示所选数据
        for (let i = bottomRow; i < topRow; i++) {
            content.children[i].classList.remove('hidden-row');
            content.children[i].classList.add('show-row');
        }

        // 定向
        currentPage = pageNo;
        let btns = document.getElementsByClassName('pagination-button-in');
        for (let i = 0; i < btns.length; i++)
            btns[i].classList.remove('pagination-button-main');
        btns[pageNo - 1].classList.add('pagination-button-main');// 为当前页的按钮 添加专属类名
    }
    // 设置左右翻页禁止提示
    setPageButtonsDisabled(pageNo);
    // 计数
    $('#page').text(currentPage + "/" + pages);
    // 设置全选状态
    checkOne();
}

// 禁止左右（上下）翻页
function setPageButtonsDisabled(pageNo) {
    // 清空状态
    $("#table-pagination-turn-left").removeClass('no-pages');
    $("#table-pagination-turn-right").removeClass('no-pages');
    // 设置状态
    if (pageNo <= 1) $('#table-pagination-turn-left').addClass('no-pages');// 不准再上一页了！
    if (pageNo >= pages) $('#table-pagination-turn-right').addClass('no-pages');// 下一页也不行！
}

// 上一页
function previous() {
    if (currentPage > 1) goToPage(currentPage - 1);
}

// 下一页
function next() {
    if (currentPage < pages) goToPage(currentPage + 1);
}

// 前往指定页数
function goToPageOf() {
    let no = $('#table-pagination-turn-goto-input').val();
    // 判断数字
    if (getNumberLength(no) === 0 || parseInt(no) === currentPage || parseInt(no) < 1 || parseInt(no) > pages) return;
    goToPage(parseInt(no));
}


/*
增加
*/
let adderId;
let adderName;
let adderGender;
let adderAcademy;
let adderMajor;
let adderTelephone;
let adderEnrolledDate;

// 展开adder
function showAdder() {
    setAdderInfo();// 加载保存信息
    adder.prop('style').display = "flex";
}

// 关闭adder
function closeAdder() {
    getAdderInfo();
    // 清空确认
    if (Boolean(adderId || adderName || adderGender || adderAcademy || adderMajor ||
        adderTelephone || adderEnrolledDate) && confirm("是否保存已输入内容？")) {
        let value = JSON.stringify({
            "id": adderId, "name": adderName, "gender": adderGender, "academy": adderAcademy,
            "major": adderMajor, "telephone": adderTelephone, "enrolledDate": adderEnrolledDate
        });
        localStorage.setItem("adderInfo", value);// 存入浏览器
    } else {
        clearAdder();
        localStorage.removeItem("adderInfo");// 移除保存项
    }
    // 关闭
    adder.prop('style').display = "none";
}

// 清空adder
function clearAdder() {
    $('#adder-id').val("");
    $('#adder-idErr').text("");
    $('#adder-name').val("");
    $('#adder-nameErr').text("");
    // $("#adder-genders").children('.pop-gender').get(2).checked = "true";// 写不来清空input的radio的选择，默认最后一项
    $('#adder-academy').val("");
    $('#adder-academyErr').text("");
    $('#adder-major').val("");
    $('#adder-majorErr').text("");
    $('#adder-telephone').val("");
    $('#adder-telephoneErr').text("");
    $('#adder-enrolledDate').val("");
    $('#adder-enrolledDateErr').text("");
}

// 获取Adder上填写的信息
function getAdderInfo() {
    adderId = $('#adder-id').val();
    adderName = $('#adder-name').val();
    adderGender = getGender();
    adderAcademy = $('#adder-academy').val();
    adderMajor = $('#adder-major').val();
    adderTelephone = $('#adder-telephone').val();
    adderEnrolledDate = $('#adder-enrolledDate').val();

    // 获取性别（adder版）
    function getGender() {
        let genders = document.getElementsByName('adder-gender');
        for (let i = 0; i < genders.length; i++) {
            if (genders[i].checked)
                return genders[i].value;
        }
        return "";
    }
}

// 加载信息显示到Adder上
function setAdderInfo() {
    // 从浏览器中获取保存内容
    let info = JSON.parse(localStorage.getItem("adderInfo"));
    if (info) {
        // 获取上次保存内容
        adderId = info.id;
        adderName = info.name;
        adderGender = info.gender;
        adderAcademy = info.academy;
        adderMajor = info.major;
        adderTelephone = info.telephone;
        adderEnrolledDate = info.enrolledDate;

        // 加载显示上次保存内容
        $('#adder-id').val(adderId);
        $('#adder-name').val(adderName);

        let gender = 2;
        if (adderGender === "男") gender = 0
        if (adderGender === "女") gender = 1;
        setGender(gender);

        $('#adder-academy').val(adderAcademy);
        $('#adder-major').val(adderMajor);
        $('#adder-telephone').val(adderTelephone);
        $('#adder-enrolledDate').val(adderEnrolledDate);
    }

    // 获取性别（adder-set版）
    function setGender(g) {
        let genders = document.getElementsByName('adder-gender');
        if (g === 0 || g === 1)
            genders[g].checked = "true";
        else
            genders[2].checked = "true";
    }
}

// 增加
function addRow() {
    // 获取数据
    getAdderInfo();
    // 校验
    let flag = checkAdder(adderId, adderName, adderAcademy, adderMajor, adderTelephone, adderEnrolledDate, 'adder');
    // 添加数据
    if (flag) {
        // 添加
        add(adderId, adderName, adderGender, adderAcademy, adderMajor, adderTelephone, adderEnrolledDate);
        addTemp(adderId, adderName, adderGender, adderAcademy, adderMajor, adderTelephone, adderEnrolledDate);
        // 整理排序
        sort();
        goToPage(pages)
        console.log("新增数据成功");
        alert("新增数据成功");
        // 清空
        clearAdder();
    } else console.log("新增数据失败");
}


/*
删除
*/

// 检查全选
// 注：为什么“全选”方法在“删除”里？因为只有删除时才会用到全选！
function checkAll() {
    // 获取全选状态
    let flag = $('.check-all')[0].checked;
    // 获取当页所有单选框
    let checkOnes = getCheckOnes();
    // 赋值全选相同状态
    for (let i = 0; i < checkOnes.length; i++) checkOnes[i].checked = flag;
    console.log("更改全选状态，全选：" + flag);
}

// 单选和全选的关联
function checkOne() {
    // 获取当页所有单选框
    let checkOnes = getCheckOnes();
    // 单选是否被全选
    let flag = true;
    for (let i = 0; i < checkOnes.length; i++) flag = flag && checkOnes[i].checked;
    // 设置全选状态
    $('.check-all')[0].checked = flag;
}

// 删除表格的 单行（按钮）
function deleteRow(row) {
    let no = row.children[1].innerText;
    if (confirm("确认删除第" + no + "行数据？")) {
        // 定向
        selectedRow = row;
        let p = currentPage;
        // 删除此行<tr>
        remove(row);
        deleteFromResult();
        // 整理排序
        sort();
        goToPage(p);
        console.log("删除第" + no + "行数据成功");
        alert("删除第" + no + "行数据成功");
    }
}

// 删除表格的 多行（复选框）
function deleteRows() {
    // 统计需删除的行数
    let nos = [];
    // 存储需删除的元素
    let rows = [];
    // 获取当页所有单选框
    let checkOnes = getCheckOnes();
    // 遍历复选框 检查状态
    for (let i = 0; i < checkOnes.length; i++)
        if (checkOnes[i].checked) {
            // 获取该行行数
            nos.push(checkOnes[i].parentNode.parentNode.childNodes[1].innerText);
            // 获取该行元素
            rows.push(checkOnes[i].parentNode.parentNode)
        }

    // 是否有选 && 确认
    if (nos.length !== 0 && confirm("确认删除第" + nos + "行数据？")) {
        for (let r of rows) {
            selectedRow = r;// 定向
            console.log(r)
            remove(r);
            deleteFromResult();
        }
        clearCheck();// 清空选择

        // 整理排序
        sort();
        console.log("删除第" + nos + "行数据成功");
        alert("删除第" + nos + "行数据成功");
    }
}

function deleteFromResult() {
    if (searchResult != null) {
        for (let i = 0; i < searchResult.length; i++) {
            if (parseInt(searchResult[i].id) === parseInt(selectedRow.children[2].innerHTML)) {
                searchResult.splice(i, 1);
                break;
            }
        }
    }
}

// 清空复选框状态（删）
function clearCheck() {
    // 全选框取消
    $('#select-all').prop('checked', false);
}

// 获取当页所有单选框
function getCheckOnes() {
    return $('.show-row').find('.check-one');
}


/*
修改 + 查看（不能修改的修改器）
*/

// 展开updater
function showUpdater(row, isUpdater) {
    // 获取数据
    setUpdater(row);
    // 展开界面
    updater.prop('style').display = "flex";
    turnUpdater(isUpdater);
}

// 关闭updater
function closeUpdater() {
    clearUpdater();
    updater.prop('style').display = "none";
}

// 获取原数据
function setUpdater(row) {
    // 定向
    selectedRow = row;

    // 获取数据并填入
    $('#updater-id').val(row.children[2].innerText);
    $('#updater-name').val(row.children[3].innerText);

    let gender = 2;
    if (row.children[4].innerText === "男") gender = 0;
    if (row.children[4].innerText === "女") gender = 1;
    setGender(gender);

    $('#updater-academy').val(row.children[5].innerText);
    $('#updater-major').val(row.children[6].innerText);
    $('#updater-telephone').val(row.children[7].innerText);
    $('#updater-enrolledDate').val(row.children[8].innerText);

    // 获取性别（updater-set版）
    function setGender(g) {
        let genders = document.getElementsByName('updater-gender');
        if (g === 0 || g === 1)
            genders[g].checked = "true";
        else
            genders[2].checked = "true";
    }
}

// 清空updater
function clearUpdater() {
    $('#updater-idErr').text("");
    $('#updater-nameErr').text("");
    $('#updater-academyErr').text("");
    $('#updater-majorErr').text("");
    $('#updater-telephoneErr').text("");
    $('#updater-enrolledDateErr').text("");
}

// 修改
function updateRow() {
    // 获取数据
    let id = $('#updater-id').prop('value');
    let name = $('#updater-name').prop('value');
    let gender = getGender();   // 性别赋有默认值，不用校验
    let academy = $('#updater-academy').prop('value');
    let major = $('#updater-major').prop('value');
    let telephone = $('#updater-telephone').prop('value');
    let enrolledDate = $('#updater-enrolledDate').prop('value');
    // 输入校验
    let flag = checkUpdater(id, name, gender, academy, major, telephone, enrolledDate);
    // 修改数据
    if (flag) {
        // 添加
        update(id, name, gender, academy, major, telephone, enrolledDate);
        // 整理排序
        let p = currentPage;
        sort();
        console.log("修改数据成功");
        alert("修改数据成功");
        closeUpdater();
        goToPage(p);
    }

    // 获取性别（updater-get版）
    function getGender() {
        let genders = document.getElementsByName('updater-gender');
        for (let i = 0; i < genders.length; i++) {
            if (genders[i].checked)
                return genders[i].value;
        }
        return "";
    }
}

// 切换修改/查看
function turnUpdater(isUpdater) {
    if (isUpdater) {
        // 是修改器，取消input的禁用
        updater.find('input').removeAttr("disabled");
        updater.find('#updater-submit').attr('style', 'display: inline;');
        updater.find('h2').text('修改学生信息填写表');
    } else {
        // 是查看器，设置input的禁用
        updater.find('input').attr("disabled", "disabled");
        updater.find('#updater-submit').attr('style', 'display: none;');
        updater.find('h2').text('查看学生信息填写表');
    }
}


/*
查询
 */
let searchTimes = 0;// 连续查询计数
let searchResult = null;// 连续查询缓存结果

// 从缓存数据中查询
function searchRow() {
    // 确认连续查询
    let target = searchResult;
    if (searchTimes === 0) target = data;
    let temp = target;// 缓存上次搜索结果

    // 获取查询选项
    let column = getSearchColumn();
    let input = getSearchInput();

    if (column !== null && input !== null) {
        let result;
        // 查找 并获取结果
        if (getSearchAccurate())
            result = searchA(target, column, input);// 精确查找
        else result = search(target, column, input)// 模糊查找

        // 展示
        console.log("查询 " + column + " 里匹配 " + input + " 的结果");
        console.log("查找到以下" + result.length + "条数据");
        if (result.length !== 0) showSearchResult(result);
        else if (temp.length !== 0) alert("没有查到任何匹配结果");
        // 本次及上次查询结果为空时
        else alert("请重置");// 走到这步就是出bug了

        // 累计查询
        if (result.length === 0) result = target;
        else searchTimes++;// 若本次查询无结果，此次查询结果及次数 不记录
        searchResult = result;

        let e = $('label[for="search-columns"]');
        if (searchTimes > 1) e.text("连续查询结果如下");
        else if (searchTimes > 0) e.text("查询结果如下");
    }
}

// 获取选项
function getSearchColumn() {
    let column = $('#search-columns .search-option:selected').text();
    if (column === "" || column.length === 0) return null;
    return column;
}

// 更改输入框
function changeSearchInput() {
    let inputElem = $('#students-manager-search-input');
    // 更改类型
    if (getSearchColumn() === "入学日期")
        inputElem.attr('type', 'date');
    else inputElem.attr('type', 'text');
}

// 确认精确查找
function getSearchAccurate() {
    return $('#students-manager-search-accurate').prop('checked');
}

// 获取内容
function getSearchInput() {
    let input = $('#students-manager-search-input').val();
    if (input === "" || input.length === 0) return null;
    return input;
}

// 展示结果
function showSearchResult(result) {
    console.log(result);
    // 重新加载数据
    setData(result);
    sort();
}

// 重置查询
function closeSearchResult() {
    // 展示初始化
    setData(data);
    sort();
    // 清空搜索缓存
    searchTimes = 0;
    searchResult = null;
    $('label[for="search-columns"]').text("查询")
}


/*
 核心
 */
function addTemp(id, name, gender, academy, major, telephone, date) {
    // 存入缓存数据
    data.push({
        id: id,
        name: name,
        gender: gender,
        academy: academy,
        major: major,
        telephone: telephone,
        enrolledDate: getGoodDate(date)
    });
}

function add(id, name, gender, academy, major, telephone, date) {
    // 创建行元素
    let tr = document.createElement('tr');
    // 行内增添数据
    $('<td class="table-checkbox"><input type="checkbox" class="check-one" onclick="checkOne()"></td>').appendTo(tr);// 多选删除用复选框
    $('<td></td>').appendTo(tr);                            // 序号
    $('<td>' + id + '</td>').appendTo(tr);                  // 学号
    $('<td>' + name + '</td>').appendTo(tr);                // 姓名
    $('<td>' + gender + '</td>').appendTo(tr);              // 性别
    $('<td>' + academy + '</td>').appendTo(tr);             // 学院
    $('<td>' + major + '</td>').appendTo(tr);               // 专业
    $('<td>' + telephone + '</td>').appendTo(tr);           // 电话号码
    $('<td>' + getGoodDate(date) + '</td>').appendTo(tr);   // 入学日期

    // 增添操作选项
    $('<td>' +
        '<button style="margin-right: 0" onclick="showUpdater(this.parentNode.parentNode, false)">查看</button>' +
        '<button style="margin-right: 0" onclick="showUpdater(this.parentNode.parentNode, true)">修改</button>' +
        '<button onclick="deleteRow(this.parentNode.parentNode)">删除</button>' +
        '</td>').appendTo(tr);

    content.appendChild(tr);
}

function remove(r) {
    // 删除缓存数据
    for (let i = 0; i < data.length; i++) {
        let d = data[i];
        // 查找缓存数据内 同一对象
        if (parseInt(d.id) === parseInt(selectedRow.children[2].innerHTML)) {
            console.log(parseInt(d.id), parseInt(selectedRow.children[2].innerHTML))
            data.splice(i, 1);// 移除数组内此元素
            break;
        }
    }
    console.log(r)
    // 删除显示数据
    content.removeChild(r);
}

function update(id, name, gender, academy, major, telephone, date) {
    // 修改缓存数据
    for (let i = 0; i < data.length; i++) {
        let d = data[i];
        // 查找缓存数据内 同一对象
        if (parseInt(d.id) === parseInt(selectedRow.children[2].innerHTML)) {
            d.id = id;
            d.name = name;
            d.gender = gender;
            d.academy = academy;
            d.major = major;
            d.telephone = telephone;
            d.enrolledDate = date;
            break;
        }
    }
    // 修改显示数据
    selectedRow.children[2].innerHTML = id;
    selectedRow.children[3].innerHTML = name;
    selectedRow.children[4].innerHTML = gender;
    selectedRow.children[5].innerHTML = academy;
    selectedRow.children[6].innerHTML = major;
    selectedRow.children[7].innerHTML = telephone;
    selectedRow.children[8].innerHTML = date;
}

function search(data, column, value) {
    // 存储结果
    let result = [];
    if (column != null) {
        let reg = new RegExp(value.toString());
        // 遍历数据 寻找匹配
        for (let i = 0; i < data.length; i++) {
            let d = data[i];
            switch (column) {
                case "学号":
                    if (d.id.toString().match(reg)) result.push(d);
                    break;
                case "姓名":
                    if (d.name.toString().match(reg)) result.push(d);
                    break;
                case "性别":
                    if (d.gender.toString().match(reg)) result.push(d);
                    break;
                case "学院":
                    if (d.academy.toString().match(reg)) result.push(d);
                    break;
                case "专业":
                    if (d.major.toString().match(reg)) result.push(d);
                    break;
                case "电话号码":
                    if (d.telephone.toString().match(reg)) result.push(d);
                    break;
                case "入学日期":
                    // 日期三项都输入完了 就没有模糊查找了
                    if (getGoodDate(d.enrolledDate) === getGoodDate(value)) result.push(d);
                    break;
                default:
                    // alert("你干了什么怎么走到这里的");
                    console.log("What you did makes you here?");
            }
        }
    }
    return result;
}

function searchA(data, column, value) {
    // 存储结果
    let result = [];
    if (column != null) {
        // 遍历数据 寻找匹配
        for (let i = 0; i < data.length; i++) {
            let d = data[i];
            switch (column) {
                case "学号":
                    if (parseInt(d.id) === parseInt(value)) result.push(d);
                    break;
                case"姓名":
                    if (d.name.toString() === value.toString()) result.push(d);
                    break;
                case "性别":
                    if (d.gender.toString() === value.toString()) result.push(d);
                    break;
                case "学院":
                    if (d.academy.toString() === value.toString()) result.push(d);
                    break;
                case "专业":
                    if (d.major.toString() === value.toString()) result.push(d);
                    break;
                case "电话号码":
                    if (d.telephone.toString() === value.toString()) result.push(d);
                    break;
                case "入学日期":
                    if (getGoodDate(d.enrolledDate) === getGoodDate(value)) result.push(d);
                    break;
                default:
                    // alert("你干了什么怎么走到这里的（精确查找版）");
                    console.log("What you did makes you here? (Accurate)");
            }
        }
    }
    return result;
}

function sort() {
    // 获取剩余行<tr>
    let rows = content.children;
    // 重新编排序号
    for (let i = 0; i < rows.length; i++) rows[i].children[1].innerText = i + 1;
    // 分页
    paginate();
    // 统计数目
    $('#sort-total').text(rows.length);
}


/*
校验用
*/

// 增加校验
function checkAdder(id, name, academy, major, telephone, enrolledDate) {
    let adr = 'adder';
    // 依次获取校验结果
    let idR = isId(id, adr);
    let nameR = isName(name, adr);
    let acaR = isAcademy(academy, adr);
    let majR = isMajor(major, adr);
    let telR = isTelephone(telephone, adr);
    let dateR = isDate(enrolledDate, adr);
    // 返回
    return idR && nameR && acaR && majR && telR && dateR;
}

// 修改校验
function checkUpdater(id, name, gender, academy, major, telephone, enrolledDate) {
    let idR = true;
    let nameR = true;
    let acaR = true;
    let majR = true;
    let telR = true;
    let dateR = true;
    let adr = 'updater';
    // 数据是否修改，是否需要校验
    if (selectedRow.children[2].innerHTML !== id) idR = isId(id, adr);
    if (selectedRow.children[3].innerHTML !== name) nameR = isName(name, adr);
    if (selectedRow.children[5].innerHTML !== gender) acaR = isAcademy(academy, adr);
    if (selectedRow.children[6].innerHTML !== major) majR = isMajor(major, adr);
    if (selectedRow.children[7].innerHTML !== telephone) telR = isTelephone(telephone, adr);
    if (selectedRow.children[8].innerHTML !== enrolledDate) dateR = isDate(enrolledDate, adr);
    // 返回
    return idR && nameR && acaR && majR && telR && dateR;
}

// 校验学号
function isId(id, adr) {
    // 修改时 学号未修改 跳过验证（避免重复学号的检验）
    if (adr === 'updater' && selectedRow.children[2].innerHTML === id) return true;

    // 检验是否为空
    if (id === "" || id == null)
        return printError(adr + '-idErr', "学号不能为空！");// false

    // 检验是否全为数字+长度合乎规范
    if (getNumberLength(id) !== 11)
        return printError(adr + '-idErr', "学号不规范！");// false

    // 检验是否被占用
    for (let i = 0; i < data.length; i++) {
        if ((parseInt(id) === parseInt(data[i].id)))
            return printError(adr + '-idErr', "此学号已被使用！");// false
    }

    return printRight(adr + '-idErr');// true
}

// 校验名字
function isName(name, adr) {
    // 检验是否为空
    if (name === "" || name == null)
        return printError(adr + '-nameErr', "姓名不能为空！");// false
    // 检验是否全为中文
    if (!isAllZh(name))
        return printError(adr + '-nameErr', "姓名不规范！");// false
    // 检验长度是否合乎规范
    if (name.length < 2 || name.length > 8)
        return printError(adr + '-nameErr', "姓名长度不规范！");// false
    return printRight(adr + '-nameErr');// true
}

// 校验学院（满足12内长度汉字即可）
function isAcademy(academy, adr) {
    // 检验是否为空
    if (academy === "" || academy == null)
        return printNo(adr + '-academyErr');// 非必填 可为空 true
    // 检验是否全为中文
    if (!isAllZh(academy))
        return printError(adr + '-academyErr', "学院名字不规范！");// false
    // 检验长度
    let l = academy.length;
    if (l < 3 || l > 12)
        return printError(adr + '-academyErr', "学院名字长度不规范！");// false
    return printRight(adr + '-academyErr');// true
}

// 校验专业（满足12内长度汉字即可）
function isMajor(major, adr) {
    // 检验是否为空
    if (major === "" || major == null)
        return printNo(adr + '-majorErr');// 非必填 可为空 true
    // 检验是否全为中文
    if (!isAllZh(major))
        return printError(adr + '-majorErr', "专业名字不规范！");// false
    // 检验长度
    let l = major.length;
    if (l < 2 || l > 12)
        return printError(adr + '-majorErr', "专业名字长度不规范！");// false
    return printRight(adr + '-majorErr');// true
}

// 校验电话号码
function isTelephone(telephone, adr) {
    if (telephone === "" || telephone == null) {
        return printNo(adr + '-telephoneErr');// 非必填 可为空 true
    }
    let l = getNumberLength(telephone);
    if (l < 8 || l > 11) {
        return printError(adr + '-telephoneErr', "电话号码不规范！");// false
    }
    return printRight(adr + '-telephoneErr');// true
}

// 校验日期（1800-2499）
function isDate(date, adr) {
    // 检验日期填写是否为空
    if (date === "" || date == null)
        return printNo(adr + '-enrolledDateErr');
    // 匹配日期格式
    if (!date.match(dateExp))
        return printError(adr + '-enrolledDateErr', "日期输入有误！");
    return printRight(adr + '-enrolledDateErr');
}

// 全中文校验
function isAllZh(str) {
    const re = /[^\u4e00-\u9fa5]/;
    return !re.test(str);
}


/*
辅助用
*/

// 显示错误输入消息
function printError(elemId, hintMsg) {
    let elem = document.getElementById(elemId);
    elem.style.color = "red";
    printE(elem, "× " + hintMsg);
    return false;
}

// 显示正确输入信息
function printRight(elemId) {
    let elem = document.getElementById(elemId);
    elem.style.color = "green";
    printE(elem, "&nbsp;√");
    return true;
}

// 撤销显示信息
function printNo(elemId) {
    let elem = document.getElementById(elemId);
    printE(elem, "");
    return true;
}

// 更改元素的innerHTML内容
function printE(e, m) {
    e.innerHTML = m;
}

// 获取数字位数 顺便检查是否全为数字
function getNumberLength(num) {
    let len = 0;
    while (num >= 1) {
        num = num / 10;
        len++;
    }
    return len;
}

// 规范日期的输出：年-月-日
function getGoodDate(date) {
    // 判断是否Date类（Date类自带0）
    if (date instanceof Date) {
        let m = parseInt((date.getMonth() + 1).toString());
        let d = parseInt(date.getDate().toString());
        return date.getFullYear().toString() + "-" + fill0(m) + "-" + fill0(d);
    }
    return date;

    // 填充0，如：2021-9-1 -> 2021-09-01
    function fill0(n) {
        if (n < 10) return "0" + n.toString();
        else return n.toString();
    }
}


// 绑定

// 表格操作选项
$('#students-manager-edit-delete').bind('click', deleteRows);
$('#students-manager-edit-add').bind('click', showAdder);
$('#search-columns').bind('click', changeSearchInput);
$('#students-manager-search-button').bind('click', searchRow);
$('#students-manager-search-cancel').bind('click', closeSearchResult);
// 表格内
$("#select-all").bind('click', checkAll);
$(".main-block").bind('click', checkOne);
// 页面操作
$("#sort-single").bind('change', paginate);
$('#table-pagination-turn-goto-button').bind('click', goToPageOf);
// 新增界面
$('#adder-close').bind('click', closeAdder);
$('#adder-submit').bind('click', addRow);
$('#adder-cancel').bind('click', closeAdder);
// 修改界面
$('#updater-close').bind('click', closeUpdater);
$('#updater-submit').bind('click', updateRow);
$('#updater-cancel').bind('click', closeUpdater);


$("#students-manager-search-input").bind('change', setInputBack);

function setInputBack() {
    let e = $('#students-manager-search-input');
    if (e.val())
        e.prop('style').boxShadow = "0 0 0 100px #f5f5f5 inset";
    else e.prop('style').boxShadow = "";
}


// 表格数据用 ↑
// ===================================分割线===================================
// 登录主页用 ↓

// $('#logout').bind('click', confirmLogout);
// $('#change-password').bind('click', changePassword);
// $('#close-account').bind('click', confirmClose);
//
// // 检查是否登录
// function isLogin() {
//     if (localStorage.getItem("is") == null || JSON.parse(localStorage.getItem("is")).isLogin !== "true") {
//         window.location.href = '../html/login.html';
//         alert("当前未登录，将退出主页");
//     }
// }
//
// // 登出确认
// function confirmLogout() {
//     if (confirm("确定退出当前登录？")) setLogout();
// }
//
// // 登出
// function setLogout() {
//     let username = JSON.parse(localStorage.getItem("is")).username;
//     let is = JSON.stringify({"username": username, "isLogin": "false"})
//     localStorage.removeItem("is");
//     localStorage.setItem("is", is);
//     isLogin();
// }
//
// // 改密码
// function changePassword() {
//     window.location.href = '../html/change-password.html';
// }
//
// // 注销
// function confirmClose() {
//     if (confirm("确定注销账号？\n您可能将永远失去此账号的信息！")) window.location.href = "../html/close-account.html";
// }